package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Api(tags = "店铺状态管理相关接口")
@RestController
@RequestMapping("/admin/shop")
@Slf4j
public class ShopAdminController {
    /** 店铺状态 0 打烊 1 营业 */
    public static final String SHOP_STATUS = "SHOP_STATUS";
    @Autowired
    RedisTemplate redisTemplate;

    /**
     * 设置店铺营业状态
     * @param status
     * @return
     */
    @ApiOperation("设置店铺营业状态")
    @PutMapping("{status}")
    public Result setStatus(@ApiParam("店铺状态") @PathVariable Integer status){
        log.info("店铺要设置的状态是 => {}",status==1?"营业中":"打烊中");
        //status => 要修改的状态  => redis
        redisTemplate.opsForValue().set(SHOP_STATUS,status);
        return Result.success();
    }

    /**
     * 获取店铺的营业状态
     * @return
     */
    @ApiOperation("获取店铺营业状态")
    @GetMapping("/status")
    public Result getStatus(){
        return Result.success(redisTemplate.opsForValue().get(SHOP_STATUS));
    }

}
